package com.hdyg.sixg.activity.mine;

import android.graphics.Bitmap;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hdyg.sixg.R;
import com.hdyg.sixg.activity.common.BaseActivity;
import com.hdyg.sixg.entry.ShareBean;
import com.hdyg.sixg.mvp.Contrant.CShare;
import com.hdyg.sixg.mvp.base.BasePresenter;
import com.hdyg.sixg.mvp.base.BaseUrl;
import com.hdyg.sixg.mvp.base.GetParamUtil;
import com.hdyg.sixg.mvp.presenter.PShare;
import com.hdyg.sixg.util.ImageLoadUtil;
import com.hdyg.sixg.util.StringUtil;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;

import butterknife.BindView;

/**
 * @author CZB
 * @describe 分享推荐
 * @time 2019/4/8 17:04
 */
public class ShareActivity extends BaseActivity implements CShare.IVShare {

    @BindView(R.id.ll_top_left)
    LinearLayout llTopLeft;
    @BindView(R.id.tvTopTitle)
    TextView tvTopTitle;
    @BindView(R.id.iv_qr_code)
    ImageView ivQrCode;
    @BindView(R.id.tv_link)
    TextView tvLink;
    @BindView(R.id.tv_share)
    TextView tvShare;
    @BindView(R.id.srl_refresh)
    SmartRefreshLayout srlRefresh;

    private CShare.IPShare mPresenter;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_share;
    }

    @Override
    protected void initView() {
        onClickListener();
        tvTopTitle.setText(R.string.share_title);
    }

    private void onClickListener() {
        srlRefresh.setOnRefreshListener(refreshLayout -> {
            srlRefresh.finishRefresh(2000);//传入false表示刷新失败
            initData();
        });
        llTopLeft.setOnClickListener(v -> finish());
        //分享
        tvShare.setOnClickListener(v -> {
            toastNotifyShort("分享");
        });
    }

    @Override
    protected void initData() {
        mPresenter.pGetInit(BaseUrl.SHARE_CODE_URL, GetParamUtil.getShareParam());
    }

    @Override
    protected void createPresenter() {
        mPresenter = new PShare(this);
    }

    @Override
    public void vGetInitSuccess(ShareBean dataBean) {

        Bitmap bitmap = StringUtil.generateQRCodeBitmap(dataBean.getShare_qrcode(),400,400);
        ivQrCode.setImageBitmap(bitmap);
        String str = String.format(getResources().getString(R.string.share_link),dataBean.getShare_qrcode());
        tvLink.setText(str);
    }
}
